<template>
  <div class="table-page-search-wrapper">
    <a-form layout="inline">
      <a-row :gutter="48">
        <a-col :xxl="16" :xl="16" :lg="16" :sm="24">
          <a-form-item label="手机号/优惠券号/AWARDID">
            <a-input
              allowClear
              v-model="queryParam.search"
              placeholder="请输入"
            />
          </a-form-item>
        </a-col>
        <!-- <a-col :xxl="8" :xl="8" :lg="8" :sm="24">
          <a-form-item label="优惠券号">
            <a-input
              allowClear
              v-model="queryParam.search"
              placeholder="请输入"
            />
          </a-form-item>
        </a-col>
        <a-col :xxl="8" :xl="8" :lg="8" :sm="24">
          <a-form-item label="AWARDID">
            <a-input
              allowClear
              v-model="queryParam.awardId"
              placeholder="请输入"
            />
          </a-form-item>
        </a-col> -->
        <a-col :xxl="24" :xl="24" :lg="24" :sm="24">
          <span class="table-page-search-submitButtons">
            <a-button style="margin-left: 8px"  @click="search">查询</a-button>
            <a-button style="margin-left: 8px" @click="reset">重置</a-button>
            <a-dropdown>
              <a-menu slot="overlay" @click="handleChange">
                <a-menu-item key="1">优惠券补发</a-menu-item>
                <a-menu-item key="2">补发记录</a-menu-item>
              </a-menu>
              <a-button style="margin-left: 8px">更多<a-icon type="down" /> </a-button>
            </a-dropdown>
            <a-button  style="margin-left: 8px" @click="handleType(3)">优惠券延期</a-button>
            <a-button  style="margin-left: 8px"  @click="handleType(1)">优惠券补打印</a-button>
            <a-button  style="margin-left: 8px" @click="handleType(2)">优惠券作废</a-button>
            <a-button type="primary" style="margin-left: 8px" @click="handleExportSendPageInfoByPageId">下载明细表</a-button>
          </span>
        </a-col>
        <!-- <a-col :xxl="24" :xl="24" :lg="24" :sm="24">
          <span class="table-page-search-submitButtons">
            批量操作：
            <a-button :disabled="!selectedRowKeys.length" style="margin-left: 8px" @click="onVoucherBatchDelay">优惠券延期</a-button>
            <a-button :disabled="!selectedRowKeys.length" v-if="sendType == 2 || sendType == 3" style="margin-left: 8px" @click="onBatchPrint">优惠券补打印</a-button>
            <a-button :disabled="!selectedRowKeys.length" style="margin-left: 8px" @click="onVoucherBatchCancel">优惠券作废</a-button>
          </span>
        </a-col> -->
      </a-row>
    </a-form>
    <a-modal v-model="visibleType" width="400px" title="请选择添加优惠券的方式" @cancel="visibleType = false" :footer="null">
      <a-button type="primary" style="width: 100%;height: 40px;margin: 20px 0 0;" @click="handleQuickAdd">
        快速添加
      </a-button>
      <a-button type="primary" style="width: 100%;height: 40px;margin: 20px 0;" @click="handleContinuousAdd">
        连续添加
      </a-button>
    </a-modal>
  </div>
</template>
<script>
import { logToken } from '@/api/headquartersCoupon/index'
export default {
  props: {
    pageId: {
      type: String,
      default: ''
    },
    selectedRowKeys: {
      type: Array,
      default: () => []
    },
    sendType: { //发券类型1微信券2礼券3纸质券
      type: [Number, String],
      default: ''
    }
  },
  data() {
    return {
      value1: '',
      type: '', // 1.补打印 2.作废 3.延期
      visibleType: false,
      queryParam:{
        search: ''
      }
    }
  },
  computed: {
  },
  created() {
  },
  methods: {
    handleChange(v) {
      if (v.key == 2) {
        this.$emit('onReissueLog')
      } else {
        this.$emit('onReissueCoupon')
      }
    },
    handleType(type) {
      this.type = type
      this.visibleType = true
    },

    onVoucherBatchDelay() {
      this.$emit('onVoucherBatchDelay')
    },

    onBatchPrint() {
      this.$emit('onBatchPrint')
    },

    onVoucherBatchCancel() {
      this.$emit('onVoucherBatchCancel')
    },

    // 快速添加
    handleQuickAdd() {
      const data = {
        type: this.type
      }
      logToken(data).then(res => {
        if (res.code == 200) {
          this.$router.push(`/headquarters-coupon/quick-add?type=${this.type}&token=${res.data}&pageId=${this.pageId}`)
        } else {
          this.$message.warning(res.msg)
        }
      })
    },

    // 连续添加
    handleContinuousAdd() {
       const data = {
        type: this.type
      }
      logToken(data).then(res => {
        if (res.code == 200) {
          this.$router.push(`/headquarters-coupon/continuous-add?type=${this.type}&token=${res.data}&pageId=${this.pageId}`)
        } else {
          this.$message.warning(res.msg)
        }
      })
    },

    search() {
      this.$emit('onSearch', this.queryParam)
    },

    handleExportSendPageInfoByPageId() {
      this.$emit('handleExportSendPageInfoByPageId', this.queryParam)
    },

    reset() {
      this.queryParam = {
        search: ''
      }
      this.$emit('onSearch', this.queryParam)
    }
  }
}
</script>
<style lang="less" scoped>
.table-page-search-submitButtons {
  display: flex;
  justify-content: flex-end;
}
</style>
